//: Playground - noun: a place where people can play

import UIKit

var str = "Hello, playground"

func extreValue(intArray:[Int])->(Int,Int){
    var max = intArray[0]
    var min = intArray[0]
    for singlevalue in intArray{
        if max > singlevalue{
            max = singlevalue
        }
        if min < singlevalue{
            min = singlevalue
        }
    }
    return (max,min)
}


print(extreValue([1,2,3,4,5,6,7,-8]))

func maybeExtreValueNil(intArray:[Int])->(Int,Int)?{
    if intArray.isEmpty {
        return nil
    }
    var max = intArray[0]
    var min = intArray[0]
    for singlevalue in intArray{
        if max > singlevalue{
            max = singlevalue
        }
        if min < singlevalue{
            min = singlevalue
        }
    }
    return (max,min)
}

//extreValue([])


//参数名

func yo(第一个参数名 name:String = "harmony"){
    print("\(name)")
}

yo(第一个参数名: "gogogogo")
yo()


//可变参数
func sum(singlevalue:Int...)->Int{
    var val = 0
    for i in singlevalue{
        val += i
    }
    return val
}

sum(1,2,3,4,5)

sum(6,7,8,9,0,9)


func swicher(inout a:Int,inout b:Int){
    let temp = a
    a=b
    b=temp
 
}
var a=4
var b=7

swicher(&a,b: &b)

a

//------------------
//函数参数类型

func operation(a:Int,b:Int)->Int{
    return a-b
}


func printoutResult(a:Int,b:Int,chaozuofu:(Int,Int)->Int){
    let result = chaozuofu(a,b)
    print("\(result)")
    

}

printoutResult(51, b: 5, chaozuofu: operation)


//将一个函数类型作为返回值

func plus(a:Int)->Int{
    return a+1
}

func minus(b:Int)->Int{
    return b-1
}

func deal(value:Bool)->(Int)->Int
{
    return value ? plus : minus
}
var ea = 100



let eb = 20

deal(false)(ea)

//嵌套函数






